#！/bin/bash
echo  this is  for  dic
declare -A dic
dic=([etcd0]="101.254.242.11" [etcd1]="101.254.242.12" [etcd2]="101.254.242.16")

echo ${dic[etcd0]}

for key in $(echo ${!dic[*]})
do
        echo "$key : ${dic[$key]}"
done
echo ==================================================================================
#while read line
#do key=${line%=*}
#value=${line#*=}
#echo $key $value
#  if [ $value == 101.254.242.12 ];then
#     echo this is $key
#  fi
#done<etcd.properties 

eps() {
                EPS=""
                while read line
                do
                key=${line%=*}
                value=${line#*=}
                EPS="${EPS}${EPS:+,}http://${value}:12379"
                done<etcd.properties
          #      echo $EPS
            }


res=$(eps)
echo ${res}
ip=`hostname -i`
id() {
              KEY=""
              while read line
              do 
              key=${line%=*}
              value=${line#*=}
              if [ ${value} = ${ip} ];then
              echo KEY=${key}
              fi
              done<etcd.properties
              echo $KEY
     }

key=$(id)
echo $key

initial_peers() {
                PEERS=""
                while read line
                do
                key=${line%=*}
                value=${line#*=}
                PEERS="${PEERS}${PEERS:+,}${key}=http://${value}:12380"
                done<etcd.properties
                echo $PEERS
            }
echo this is peers: $(initial_peers)
